package com.sy.service.purchase.impl;

import com.alibaba.excel.EasyExcel;
import com.sy.bean.purchase.MaterialExcel;
import com.sy.bean.purchase.QueryStatistics;
import com.sy.bean.purchase.Statistics;
import com.sy.bean.purchase.StatisticsExcel;
import com.sy.common.bean.PageBean;
import com.sy.common.crud.BaseServiceImpl;
import com.sy.mapper.purchase.StatisticsMapper;
import com.sy.service.purchase.StatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.util.List;
import java.util.Map;

@Service
public class StatisticsServiceImpl extends BaseServiceImpl<Statistics, StatisticsMapper> implements StatisticsService {

    @Autowired
    StatisticsMapper  statisticsMapper;

    @Autowired
    HttpServletRequest request;


    @Override
    public String export(Map map) {
        List<StatisticsExcel> list = statisticsMapper.export(map);
        String root=request.getSession().getServletContext().getRealPath("/")+"/excel";
        File file=new File(root);
        if (!file.exists())
            file.mkdirs();
        String fileName= file.getAbsolutePath()+"/商品采购统计表.xlsx";
        EasyExcel.write(fileName, MaterialExcel.class)
                .sheet("商品采购统计表")
                .doWrite(()->{
                    return list;
                });
        return "/excel/商品采购统计表.xlsx";
    }
}
